package com.zysc.processflow.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zysc.processflow.common.base.ResultBody;
import com.zysc.processflow.entity.Role;
import com.zysc.processflow.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zysc.processflow.common.base.BaseController;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author 正元智慧城市_
 * @since 2023-02-20
 */
@Api(value = "角色管理表", tags = "角色管理表")
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController<Role> {
    @Autowired
    IRoleService service;
    public RoleController(IRoleService service) {
        super(service);
    }
    @ApiOperation("获取角色权限列表(支持分页)")
    @GetMapping(value = "GetRolePermission")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "pageIndex", name = "pageIndex", dataType = "String"),
            @ApiImplicitParam(value = "pageSize", name = "pageSize", dataType = "String"),
            @ApiImplicitParam(value = "角色名", name = "rolename", dataType = "String"),
    })
    public ResultBody GetRolePermission(@RequestParam(value = "pageIndex",required = false)Integer pageIndex ,
                                      @RequestParam(value = "pageSize",required = false)Integer pageSize ,
                                      @RequestParam(value = "rolename",required = false)String rolename) {
        if (pageIndex != null && pageSize != null) {
            IPage<Role> page = new Page<>(pageIndex, pageSize);
            List<Role> res = service.GetRolePermission(page,rolename);
            return ResultBody.Success(res, page.getTotal());
        } else {
            List<Role> res = service.GetRolePermission(null,rolename);
            return ResultBody.Success(res);
        }
    }

}
